package com.tianji.learning.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tianji.common.utils.CollUtils;
import com.tianji.learning.domain.po.PointsBoardSeason;
import com.tianji.learning.mapper.PointsBoardSeasonMapper;
import com.tianji.learning.service.IPointsBoardSeasonService;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xzh
 * @since 2024-03-18
 */
@Service
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class PointsBoardSeasonServiceImpl extends ServiceImpl<PointsBoardSeasonMapper, PointsBoardSeason> implements IPointsBoardSeasonService {

    /**
     * 查询所有赛季名称等信息
     * @return
     */
    @Override
    public List<PointsBoardSeason> queryBoardSeasonList() {
        List<PointsBoardSeason> list = lambdaQuery().list();
        if (CollUtils.isEmpty(list)){
            CollUtils.emptyList();
        }
        return list;
    }

    /**
     * 根据时间获得赛季id
     * @param date
     * @return
     */
    @Override
    public Integer queryBoardSeasonId(LocalDate date) {
        PointsBoardSeason boardSeason = lambdaQuery().le(PointsBoardSeason::getEndTime, date)
                .ge(PointsBoardSeason::getBeginTime, date)
                .one();
       if (boardSeason==null){
           return null;
       }
        return boardSeason.getId();
    }
}
